// _Test6_Webcam.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include "stdio.h"

int _tmain(int argc, _TCHAR* argv[])
{
	CvCapture* capture  = 0;

	IplImage* frame = 0;
	int key = 0;

	capture = cvCaptureFromCAM(0);
	if(!capture)
	{
		printf("Can not initialize webcam. \n");
		return 0;
	}
	CvSize size = cvSize((int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH),(int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT));
	printf("%d, %d\n",size.width,size.height);
	CvVideoWriter* writer = cvCreateVideoWriter("D:\\output.avi",CV_FOURCC('M','J','P','G'),30,size);

	cvNamedWindow("Main",CV_WINDOW_AUTOSIZE);



	while (1)
	{
		frame = cvQueryFrame(capture);
		if(!frame)
			break;
		cvShowImage("Main",frame);
		cvWriteFrame(writer, frame);

		key = cvWaitKey(33);
		if(key==27)
			break;
	}


	cvReleaseVideoWriter(&writer);
	cvReleaseCapture(&capture);
	cvDestroyWindow("Main");
	return 0;

}


